{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "797bd874",
   "metadata": {},
   "outputs": [],
   "source": [
    "# imports\n",
    "import os\n",
    "from typing import Dict, List\n",
    "from dotenv import load_dotenv\n",
    "from IPython.display import display, Markdown\n",
    "from litellm import completion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "38c5c11c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load environment variables\n",
    "load_dotenv(override=True)\n",
    "\n",
    "# Keys (optional: LiteLLM reads from env automatically if set)\n",
    "openai_api_key = os.getenv(\"OPENAI_API_KEY\")\n",
    "anthropic_api_key = os.getenv(\"ANTHROPIC_API_KEY\")\n",
    "# Prefer GEMINI_API_KEY for LiteLLM's Gemini provider\n",
    "gemini_api_key = os.getenv(\"GEMINI_API_KEY\") or os.getenv(\"GOOGLE_API_KEY\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e8187cb4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Models\n",
    "models: Dict[str, str] = {\n",
    "    \"gpt\":    \"gpt-4o-mini\",\n",
    "    \"claude\": \"anthropic/claude-3-haiku-20240307\",\n",
    "    \"gemini\": \"gemini/gemini-2.0-flash\",\n",
    "}\n",
    "\n",
    "# System prompts\n",
    "prompts: Dict[str, str] = {\n",
    "    \"Athena\": (\n",
    "        \"You are Athena, a systems thinker. \"\n",
    "        \"Map assumptions, constraints, and risks. \"\n",
    "        \"Be concise; use numbered points. \"\n",
    "        \"End with one clarifying question. \"\n",
    "        \"Keep responses short (1–2 sentences), but specific.\"\n",
    "    ),\n",
    "    \"Blaze\": (\n",
    "        \"You are Blaze, a pragmatic engineer. \"\n",
    "        \"Propose implementable steps, quick tests, and simple metrics. \"\n",
    "        \"Give costs/effort at a high level. \"\n",
    "        \"End with a concrete next action. \"\n",
    "        \"Keep responses short (1–2 sentences), but insightful.\"\n",
    "    ),\n",
    "    \"Cypher\": (\n",
    "        \"You are Cypher, a critical evaluator. \"\n",
    "        \"Challenge claims and surface uncertainties. \"\n",
    "        \"Suggest minimal validation experiments or data checks. \"\n",
    "        \"Avoid repeating others verbatim. \"\n",
    "        \"Keep responses short (1–2 sentences), but imaginative.\"\n",
    "    ),\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "21f4e64d",
   "metadata": {},
   "outputs": [],
   "source": [
    "def chat_with_agent(\n",
    "    role: str,\n",
    "    message: str,\n",
    "    models: Dict[str, str],\n",
    "    prompts: Dict[str, str],\n",
    ") -> str:\n",
    "    \"\"\"\n",
    "    Generic chat handler for agents Athena, Blaze, Cypher.\n",
    "    \"\"\"\n",
    "    role_to_model = {\"Athena\": \"gpt\", \"Blaze\": \"claude\", \"Cypher\": \"gemini\"}\n",
    "    model_key = role_to_model.get(role)\n",
    "    if not model_key or model_key not in models:\n",
    "        raise ValueError(f\"Unknown model for role: {role}\")\n",
    "\n",
    "    try:\n",
    "        resp = completion(\n",
    "            model=models[model_key],\n",
    "            messages=[\n",
    "                {\"role\": \"system\", \"content\": prompts[role]},\n",
    "                {\"role\": \"user\", \"content\": message},\n",
    "            ],\n",
    "        )\n",
    "        return resp[\"choices\"][0][\"message\"][\"content\"]\n",
    "    except Exception as e:\n",
    "        print(f\"[Error in {role}]: {e}\")\n",
    "        return \"An error occurred while generating a response.\"\n",
    "\n",
    "# Seed transcript with the two initial messages\n",
    "transcript: List[str] = [\n",
    "    'Blaze: Hello Athena, how are you today?',\n",
    "    \"Cypher: Hi Athena, I was wondering if you could help me with a creative project I'm working on.\"\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f3878c73",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "## Three-Way AI Conversation"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Initial Messages:**"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "*Blaze: Hello Athena, how are you today?\n",
       "Cypher: Hi Athena, I was wondering if you could help me with a creative project I'm working on.*"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Athena:** 1. Assumptions: \n",
       "   - Cypher is seeking guidance in creativity.\n",
       "   - The project has a defined objective or target audience.\n",
       "\n",
       "2. Constraints: \n",
       "   - Time limitations for project completion.\n",
       "   - Available resources (tools, budget, skills).\n",
       "\n",
       "3. Risks: \n",
       "   - Possibility of creative blocks or lack of inspiration.\n",
       "   - Alignment of the project with the intended audience's interests.\n",
       "\n",
       "What is the specific nature of your creative project?"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Blaze:** Blaze here. To help with your creative project, I'd need more details on the specific nature of it - what are you trying to create, for whom, and what's the goal? Without those details, I can only provide general suggestions:\n",
       "\n",
       "Quick tests could include surveys or user interviews to gauge initial reactions and interest. Simple metrics might track engagement, shares, or reviews once you have a prototype. \n",
       "\n",
       "Costs/effort will depend on the scope, but focus first on low-cost experiments to validate your core ideas. The next concrete step is to clearly define your project objectives and target audience. Let me know the specifics, and I can provide more tailored recommendations."
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Cypher:** Athena identifies project assumptions, constraints, and risks. Can we test these assumptions—is creativity *actually* the bottleneck?\n",
       "\n",
       "Blaze suggests surveys/interviews to gauge initial reaction. Before that, shouldn't we validate if the *problem* being addressed resonates with the target audience?\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Athena:** 1. Assumptions:  \n",
       "   - Creativity is the main challenge in Cypher's project.  \n",
       "   - The target audience experiences a relevant problem that warrants a solution.\n",
       "\n",
       "2. Constraints:  \n",
       "   - Limited access to feedback mechanisms (surveys/interviews).\n",
       "   - Potential bias in assumptions about the audience's needs.\n",
       "\n",
       "3. Risks:  \n",
       "   - Misidentification of the actual problem may lead to wasted resources.\n",
       "   - Feedback may be skewed if not executed with comprehensive outreach.\n",
       "\n",
       "What methods do you plan to use to validate whether the problem resonates with the target audience?"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Blaze:** Blaze here. Great points, Athena. Before diving into creative solutions, we should first validate the problem itself. Here are a few steps I'd recommend:\n",
       "\n",
       "1. Conduct user interviews and focus groups to understand the target audience's pain points, needs, and current solutions (or lack thereof). This will help confirm if there's a real problem worth solving.\n",
       "\n",
       "2. Analyze relevant industry data, trends, and competitor offerings to assess market demand and opportunity. Look for unmet needs or areas for improvement.\n",
       "\n",
       "3. Create low-fidelity prototypes or concepts and test them with potential users. Gauge their reactions, feedback, and willingness to engage with a solution.\n",
       "\n",
       "4. Prioritize the most promising problem areas based on user feedback and market data. This will help focus your creative efforts on the right challenge.\n",
       "\n",
       "The next concrete step is to develop a structured user research plan to validate the problem statement. I'm happy to provide more details on research methods and metrics if needed. Let me know how else I can help."
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Cypher:** Blaze suggests user interviews & prototypes, but how do we ensure these represent diverse perspectives within the target audience, avoiding skewed validation?\n",
       "\n",
       "Athena flags limited access to feedback and potential bias. Can we quantify the confidence level in the initial assumptions before investing in extensive user research?\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Athena:** 1. Assumptions:  \n",
       "   - Diverse perspectives within the target audience are accessible for interviews and prototypes.  \n",
       "   - Initial assumptions can be quantified in a meaningful way.\n",
       "\n",
       "2. Constraints:  \n",
       "   - Resource limitations may hinder the ability to reach a broad spectrum of the target audience.  \n",
       "   - Time constraints may restrict extensive validation processes.\n",
       "\n",
       "3. Risks:  \n",
       "   - Failing to gather varied input could lead to a narrow understanding of audience needs.  \n",
       "   - Overconfidence in initial assumptions might result in inadequate research or validation efforts.\n",
       "\n",
       "What criteria will you use to ensure diverse representation in your user research?"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Blaze:** Here is Blaze's response:\n",
       "\n",
       "Blaze: Good point about ensuring diverse perspectives, Athena. Here are a few steps to address that:\n",
       "\n",
       "1. Develop a user persona framework to map out key demographic, psychographic, and behavioral segments within the target audience. This will help identify underrepresented groups.\n",
       "\n",
       "2. Partner with community organizations, online forums, or influencers to broaden the reach of your user interviews and prototype testing. This can help access harder-to-reach segments.\n",
       "\n",
       "3. Implement randomized sampling techniques and quotas to ensure a balanced mix of participants during research activities.\n",
       "\n",
       "4. Before investing heavily, do a quick \"confidence check\" on the initial assumptions. Assign confidence levels (e.g. 70% sure of problem, 50% sure of target audience) and identify the riskiest assumptions that need immediate validation.\n",
       "\n",
       "The next step is to finalize the user research plan, incorporating tactics to achieve diverse representation. I'd be happy to discuss specific methods and metrics if you have more details on the project. Let me know how else I can help."
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Cypher:** Cypher: Blaze suggests personas & partnerships for diversity, but how do we measure the *impact* of these efforts on the breadth of feedback received?\n",
       "\n",
       "Athena proposes a \"confidence check\". Can we use a simple Bayesian approach to update this confidence level after each research iteration, guiding further investigation?\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Athena:** 1. Assumptions:  \n",
       "   - Diverse representation will lead to richer and more relevant feedback.  \n",
       "   - Feedback quality can be effectively measured and improved through structured approaches.\n",
       "\n",
       "2. Constraints:  \n",
       "   - Limited metrics may exist to quantify the impact of diversity on feedback.  \n",
       "   - The complexity of analysis may increase with multiple iterations.\n",
       "\n",
       "3. Risks:  \n",
       "   - Insufficient measurement may lead to an inability to assess the effectiveness of diversity efforts.  \n",
       "   - Over-reliance on quantitative measures may overlook qualitative insights that are valuable.\n",
       "\n",
       "What specific metrics or indicators do you intend to track to measure the impact of diversity on feedback quality?"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Blaze:** Blaze here. Let me offer a pragmatic approach to measuring the impact of diversity on your user research:\n",
       "\n",
       "1. Metrics for Diversity:\n",
       "   - Track the demographic, psychographic, and behavioral spread of your participant pool.\n",
       "   - Measure the proportion of underrepresented groups included in interviews and testing.\n",
       "\n",
       "2. Metrics for Feedback Quality:\n",
       "   - Assess the breadth and depth of insights gathered - e.g., number of unique pain points identified, range of feature preferences.\n",
       "   - Monitor the frequency of new vs. repeated feedback across iterations.\n",
       "   - Qualitatively analyze the richness and relevance of the input.\n",
       "\n",
       "3. Bayesian Confidence Updating:\n",
       "   - Start with your initial confidence levels on key assumptions.\n",
       "   - After each round of research, update these confidence scores based on the new data gathered.\n",
       "   - This will help you focus further efforts on the riskiest, lowest-confidence areas.\n",
       "\n",
       "The next step is to finalize your user research plan, including specific diversity targets and quality metrics. I'm happy to provide more details on operationalizing these approaches. Let me know if you need any clarification or have additional questions."
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Cypher:** Cypher: Blaze suggests metrics like \"unique pain points\" to measure feedback quality. But how do we control for the *articulation skill* of participants affecting the *perceived* uniqueness, not the actual problem diversity?\n",
       "\n",
       "Athena highlights limitations with quantifying feedback. Before formalizing Bayesian updating, could we simply visualize the distribution of opinions across demographic groups to quickly identify gaps?\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Athena:** 1. Assumptions:  \n",
       "   - The ability of participants to articulate their feedback varies and influences perceived uniqueness.  \n",
       "   - Demographic distributions can effectively highlight gaps in feedback diversity.\n",
       "\n",
       "2. Constraints:  \n",
       "   - Limited tools or methods may be available for visualizing feedback distributions.  \n",
       "   - Participant reluctance to share may affect the richness of insights gathered.\n",
       "\n",
       "3. Risks:  \n",
       "   - Overemphasis on visual distributions may overlook qualitative feedback nuances.  \n",
       "   - Misinterpretation of data visualization could lead to misguided conclusions about diversity or gaps.\n",
       "\n",
       "What visualization techniques do you plan to use to effectively display and analyze the distribution of opinions across demographic groups?"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Blaze:** Blaze here with a pragmatic approach:\n",
       "\n",
       "1. Visualize Feedback Distribution:\n",
       "   - Create simple bar charts or histograms to plot the frequency of feedback themes/pain points across different demographic segments of your user base.\n",
       "   - This will quickly highlight areas where certain groups are underrepresented or have divergent perspectives.\n",
       "\n",
       "2. Complement with Qualitative Insights:\n",
       "   - Supplement the quantitative visualizations with detailed notes and quotes from the user interviews.\n",
       "   - Analyze the nuances and context behind the feedback, which can uncover hidden insights missed by the metrics alone.\n",
       "\n",
       "3. Iterative Improvements:\n",
       "   - After the initial visualization, identify gaps in demographic representation and focus your next round of user research on those underrepresented segments.\n",
       "   - Refine your interview techniques to better capture the articulation abilities of participants, rather than just relying on the perceived uniqueness of feedback.\n",
       "\n",
       "4. Bayesian Confidence Updating:\n",
       "   - Once you have a richer set of diverse user insights, you can apply Bayesian analysis to update your initial confidence levels on key assumptions.\n",
       "   - This will help you prioritize the most critical areas requiring further validation before investing heavily in the creative solution.\n",
       "\n",
       "The next step is to create a simple dashboard to visualize the feedback distribution across your target audience segments. I'm happy to provide more guidance on effective data visualization techniques. Let me know if you have any other questions!"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "**Cypher:** Cypher: Cypher: Blaze suggests histograms & qualitative notes for analysis. Can we pre-define a taxonomy of potential articulation difficulties (e.g., language barriers, tech jargon) to categorize & account for them upfront?\n",
       "\n",
       "Athena flags potential data misinterpretation. Before building dashboards, could we run a pilot visualization session with a small, diverse group to validate its clarity and prevent unintended biases?\n",
       "\n",
       "Athena: 1. Assumptions:\n",
       "   - A pre-defined taxonomy can effectively capture the range of articulation difficulties.\n",
       "   - A pilot session can highlight visualization biases.\n",
       "\n",
       "2. Constraints:\n",
       "   - Taxonomy creation requires expertise.\n",
       "   - Pilot participation depends on availability.\n",
       "\n",
       "3. Risks:\n",
       "   - An incomplete taxonomy leads to incomplete analysis.\n",
       "   - A biased pilot group might not catch all visualization issues.\n",
       "\n",
       "How will the taxonomy of articulation difficulties be developed, and what measures will be taken to ensure its comprehensiveness?\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Render header\n",
    "display(Markdown(\"## Three-Way AI Conversation\"))\n",
    "display(Markdown(\"**Initial Messages:**\"))\n",
    "display(Markdown(\"*\" + \"\\n\".join(transcript) + \"*\"))\n",
    "display(Markdown(\"---\"))\n",
    "\n",
    "# Run 5 rounds where Athena responds to the ongoing transcript,\n",
    "# then Blaze responds, then Cypher responds.\n",
    "for i in range(5):\n",
    "    context = \"\\n\".join(transcript)\n",
    "\n",
    "    athena_reply = chat_with_agent(\"Athena\", context, models, prompts)\n",
    "    display(Markdown(f\"**Athena:** {athena_reply}\"))\n",
    "    transcript.append(f\"Athena: {athena_reply}\")\n",
    "\n",
    "    context = \"\\n\".join(transcript)\n",
    "    blaze_reply = chat_with_agent(\"Blaze\", context, models, prompts)\n",
    "    display(Markdown(f\"**Blaze:** {blaze_reply}\"))\n",
    "    transcript.append(f\"Blaze: {blaze_reply}\")\n",
    "\n",
    "    context = \"\\n\".join(transcript)\n",
    "    cypher_reply = chat_with_agent(\"Cypher\", context, models, prompts)\n",
    "    display(Markdown(f\"**Cypher:** {cypher_reply}\"))\n",
    "    transcript.append(f\"Cypher: {cypher_reply}\")\n",
    "\n",
    "    if i < 4:\n",
    "        display(Markdown(\"---\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "52e588bd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "llms_sept25",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
